# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta

from jms.dm.dm_sqs_false_sign_detail_dt import jms_dm__dm_sqs_false_sign_detail_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dim.dim_sys_network_area_base import jms_dim__dim_sys_network_area_base
from jms.dm.dm_network_taking_union_sign_hour_sum_dt import jms_dm__dm_network_taking_union_sign_hour_sum_dt

# --        jms_ods.work_order      普通工单表
# --        jms_ods.project_work_order  平台工单表
# --        jms_dwd.dwd_tab_barscan_collect_base_dt           操作代收表
# --        jms_dwd.dwd_tab_barscan_sign_base_dt           操作签收表
# --        jms_dwd.dwd_tab_reback_transfer_express_base_dt     退转件表
# --        jms_dwd.dwd_yl_oms_oms_order_incre_dt     订单表
# --        jms_dwd.dwd_oms_order_performance_main_base_dt     订单履约表
# --        jms_dim.dim_sys_network_area_base     片区
# --        jms_dim.dim_network_whole_massage     组织表

jms_dm__dm_sqs_false_sign_sum_dt = SparkSqlOperator(
    task_id='jms_dm__dm_sqs_false_sign_sum_dt',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(minutes=30),
    email=['jokic.wang@jtexpress.com'],
    name='jms_dm__dm_sqs_false_sign_sum_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_sqs_false_sign_sum_dt/execute.hql',
    driver_memory='4G',
    driver_cores=1,
    executor_cores=4,
    executor_memory='5G',
    num_executors=8,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 10,
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead': '2G',
        'spark.sql.shuffle.partitions': 150,
        'spark.yarn.maxAppAttempts': 1
    },
    hiveconf={
           'hive.exec.dynamic.partition': 'true',  # 动态分区
           'hive.exec.dynamic.partition.mode': 'nonstrict',
           'hive.exec.max.dynamic.partitions': 35,  # 每天生成 20 个分区
           'hive.exec.max.dynamic.partitions.pernode': 35  # 每天生成 20 个分区
       },
)

jms_dm__dm_sqs_false_sign_sum_dt << [
    jms_dm__dm_sqs_false_sign_detail_dt,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_sys_network_area_base,
    jms_dm__dm_network_taking_union_sign_hour_sum_dt
]
